import request from '@/utils/request'

const api_prefix = '/admin/system/sysRole'

export default {

  /**
   * 根据用户id查询用户已分配的角色
   *
   * @param idRequest 用户id
   * @returns {*}
   */
  getRolesByUserId(idRequest) {
    return request({
      url: `${api_prefix}/toAssign`,
      method: 'get',
      params: { id: idRequest }
    })
  },

  /**
   * 分配角色
   *
   * @param assignRoleRequest
   * @returns {*}
   */
  assignRoles(assignRoleRequest) {
    return request({
      url: `${api_prefix}/doAssign`,
      method: 'post',
      data: assignRoleRequest
    })
  },

  /**
   *  创建角色
   * @param sysRoleAddRequest
   * @returns {*}
   */
  addRole(sysRoleAddRequest) {
    return request({
      url: `${api_prefix}/add`,
      method: 'post',
      data: sysRoleAddRequest
    })
  },

  /**
   * 删除角色
   *
   * @param deleteRequest
   * @returns {*}
   */
  deleteRole(deleteRequest) {
    return request(({
      url: `${api_prefix}/delete`,
      method: 'post',
      data: deleteRequest
    }))
  },

  /**
   * 批量删除角色
   *
   * @param ids
   * @returns {*}
   */
  batchDeleteRole(idList) {
    return request(({
      url: `${api_prefix}/batchDelete`,
      method: 'post',
      data: idList
    }))
  },

  /**
   * 更新角色
   *
   * @param sysRoleUpdateRequest
   * @returns {*}
   */
  updateRole(sysRoleUpdateRequest) {
    return request(({
      url: `${api_prefix}/update`,
      method: 'post',
      data: sysRoleUpdateRequest
    }))
  },

  /**
   * 根据 id 获取角色
   *
   * @param id
   * @returns {*}
   */
  getRoleById(id) {
    return request(({
      url: `${api_prefix}/get`,
      method: 'get',
      params: { id }
    }))
  },

  /**
   * 获取角色列表
   *
   * @param sysRoleQueryRequest
   * @returns {*}
   */
  listRole(sysRoleQueryRequest) {
    return request(({
      url: `${api_prefix}/list`,
      method: 'get',
      param: sysRoleQueryRequest
    }))
  },

  /**
   * 分页获取角色列表
   *
   * @param current
   * @param pageSize
   * @param sysRoleQueryRequest
   * @returns {*}
   */
  listRoleByPage(current, pageSize, sysRoleQueryRequest) {
    return request(({
      url: `${api_prefix}/list/page`,
      method: 'get',
      params: { current, pageSize, ...sysRoleQueryRequest }
    }))
  }

}
